const {initConnection} = require('../util/initMq')

async function producer() {
    // 交换机名称
    const exchange = 'testExchange';
    // 队列名称
    const queueName = 'testQueueTwo';
    // 死信队列交换机名称
    const exchangeDLX = 'dram_dxl';
    // 死信队列路由 一个队列queue可以按照不同的route进行分发
    const routingKeyDLX = 'testRoutingKeyTwo';

    const connection = await initConnection();
    // 创建一个频道
    const ch = await connection.createChannel();
    // 绑定一个交换机 类型为direct
    await ch.assertExchange(exchange, 'direct', {durable: true});
    // 设定队列
    const queueResult = await ch.assertQueue(queueName, {
        exclusive: false,
        deadLetterExchange: exchangeDLX,
        deadLetterRoutingKey: routingKeyDLX,
    });
    await ch.bindQueue(queueResult.queue, exchange);
    console.log(queueResult.queue)
    const msg = 'hello world two!';
    console.log('producer msg：', msg);
    await ch.sendToQueue(queueResult.queue, Buffer.from(msg), {
        expiration: 3000
    });
    ch.close();
}


producer();
